﻿<template>
	<div class="Phone7Segment-container">
		<el-card shadow="hover">
			<el-form :model="state.queryParams" ref="queryForm" :inline="true">
				<el-form-item :label-width='70' label="手机号段" prop="name">
					<el-input placeholder="手机号段" clearable class='ml10' @keyup.enter="handleQuery"
						v-model="state.queryParams.phone7"  :maxlength="7"/>
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'phone7Segment:query'">
							查询 </el-button>
						<el-button icon="ele-Refresh" @click="resetQuery" v-auth="'phone7Segment:query'"> 重置
						</el-button>
					</el-button-group>
				</el-form-item>
			</el-form>
		</el-card>

		<el-card shadow="hover" style="margin-top: 8px">
            <div style="margin: -8px 0 10px 0;">
                <el-button type="success" plain icon="ele-Plus" @click="openAddPhone7Segment"
                           v-auth="'phone7Segment:add'"> 新增 </el-button>
            </div>
			<el-table :data="state.data" style="width: 100%" v-loading="state.loading" tooltip-effect="light"
				row-key="id" border stripe highlight-current-row>
				<el-table-column header-align="center" type="index" label="序号" width="55" align="center" />
				<el-table-column header-align="center" prop="phone7" label="手机号码前7位" width="150" show-overflow-tooltip />
				<el-table-column header-align="center" prop="province" width="82" label="省份" show-overflow-tooltip />
				<el-table-column header-align="center" prop="city" width="82" label="城市" show-overflow-tooltip />
				<el-table-column header-align="center" prop="operatorPlatform" width="80" label="运营商" show-overflow-tooltip>
					<template #default="scope">
						<el-tag type="success" v-if="scope.row.operatorPlatform === 1">移动</el-tag>
						<el-tag type="warning" v-else-if="scope.row.operatorPlatform === 2">联通</el-tag>
						<el-tag type="info" v-else-if="scope.row.operatorPlatform === 3">电信</el-tag>
						<el-tag type="error" v-else-if="scope.row.operatorPlatform === 4">广电</el-tag>
						<el-tag type="info" v-else-if="scope.row.operatorPlatform === 0">未知</el-tag>
						<el-tag type="error" v-else>未知</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="100" align="center" fixed="right" show-overflow-tooltip  >
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text type="primary"
							@click="openEditPhone7Segment(scope.row)" v-auth="'phone7Segment:update'"> 编辑 </el-button>
						<!-- <el-button icon="ele-Delete" size="small" text type="danger"
							@click="delPhone7Segment(scope.row)" v-auth="'phone7Segment:delete'"> 删除 </el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
				:page-sizes="[20, 50, 100]" v-model:current-page="state.queryParams.pageNum" background
				v-model:page-size="state.queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="state.total" />
			<EditPhone7Segment ref="editPhone7SegmentRef" :title="state.editTitle" />
		</el-card>
	</div>
</template>

<script lang="ts" setup name="Phone7Segment">
import { onMounted, onUnmounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import mittBus from '/@/utils/mitt';
import EditPhone7Segment from '/@/views/common/Phone7Segment/component/editPhone7Segment.vue';

import { Phone7Segment } from '/@/api/models';
import SysPhone7SegmentApi from '/@/api/common/Phone7Segment';

// 定义变量内容
const editPhone7SegmentRef = ref<InstanceType<typeof EditPhone7Segment>>();
const state = reactive({
	loading: false,
	data: [] as Array<Phone7Segment>,
	total: 0 as any,
	queryParams: {
        phone7: undefined,
		pageNum: 1,
		pageSize: 20,
	},
	editTitle: '',
});

onMounted(async () => {
	mittBus.on('submitRefresh', () => {
		handleQuery();
	});
});

onUnmounted(() => {
	mittBus.off('submitRefresh');
});

// 查询操作
const handleQuery = async () => {
	state.loading = true;
	const res = await SysPhone7SegmentApi().queryRecord(state.queryParams);
	state.data = res.data.result.items ?? [];
	state.total = res.data.result?.total;
	state.loading = false;
};

// 重置操作
const resetQuery = () => {
	state.queryParams.phone7 = undefined;
	handleQuery();
};

// 打开新增页面
const openAddPhone7Segment = () => {
	state.editTitle = '添加';
	editPhone7SegmentRef.value?.openDialog({ status: 1 },0);
};

// 打开编辑页面
const openEditPhone7Segment = (row: Phone7Segment) => {
	let seg = 1;
	state.editTitle = '编辑';
	editPhone7SegmentRef.value?.openDialog(row, seg);
};

// 改变页面容量
const onHandleSizeChange = (val: number) => {
	state.queryParams.pageSize = val;
	handleQuery();
};

// 改变页码序号
const onHandleCurrentChange = (val: number) => {
	state.queryParams.pageNum = val;
	handleQuery();
};

</script>
